﻿Shader "CookbookShaders/NormalMap" {
	Properties {
		_MainTint ("Main Tint", Color) = (1, 1, 1, 1)
		_NormalMap ("Normal Map", 2D) = "bump"{}
		_NormalMapIntensity ("Normal Map Intensity", Range(0, 10)) = 2
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		#pragma surface surf Lambert

		float4 _MainTint;
		sampler2D _NormalMap;
		float _NormalMapIntensity;

		struct Input {
			float2 uv_NormalMap;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			float3 normalMap = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));
			normalMap = float3(normalMap.x * _NormalMapIntensity, normalMap.y * _NormalMapIntensity, normalMap.z);
			o.Normal = normalMap.rgb;
			o.Albedo = _MainTint.rgb;
			o.Alpha = _MainTint.a;
		}
		ENDCG
	}
	FallBack "Diffuse"
}
